useObjects
The useObjects hook provides access to the ObjectStore application state, enabling dynamic configuration and management of objects within a scene. This hook is part of the @promaton/scan-viewer package and offers a comprehensive interface for interacting with objects in the viewer.
Interface: ObjectStore
The ObjectStore interface exposes various properties and methods to manage objects, their states, and interactions. Below is a detailed breakdown of its features:
Properties and Methods
addToSelection(selection, force?)
Adds objects to the current selection.
- Parameters:
selection:ViewerSelection- The objects to be added to the selection.force?:boolean- Iftrue, bypasses theuseConfigs.enableObjectSelectionsetting.
- Returns:
void
deleteObject(id)
Deletes an object from the store by its ID.
- Parameters:
id:string- The ID of the object to delete.
- Returns:
void
deleteObjects(ids)
Deletes multiple objects from the store by their IDs.
- Parameters:
ids:string[]- An array of object IDs to delete.
- Returns:
void
groupState
Represents the state of groups used in objects.
highlight
A temporary state to highlight an object without selecting it.
- Type:
null | string
objectEditor
Controls the popover for editing the configuration of a targeted object.
objectOverrides
Overrides the configured properties of objects, useful for temporary styling.
objects
Stores a map of ViewerObjects by their IDs.
- Type:
Record<string, undefined | ViewerObject>
onObjectClicked(id, position, viewportID)?
Optional callback triggered when an object is clicked.
- Parameters:
id:string- The ID of the clicked object.position:Vector3- The position of the clicked object.viewportID:string- The ID of the viewport where the click occurred.
- Returns:
void
removeFromSelection(id)
Removes an object from the selection by its ID.
- Parameters:
id:string- The ID of the object to remove.
- Returns:
void
scanMetadata
Stores metadata about the currently loaded CBCT scan.
selection
Represents the collection of selected objects.
setGroupState(state, replace?)
Updates the state of object groups.
- Parameters:
state:GroupState- The new group state.replace?:boolean- Iftrue, replaces the existing state instead of merging.
- Returns:
void
setHighlight(id)
Sets the highlighted object by its ID.
- Parameters:
id:null | string- The ID of the object to highlight.
- Returns:
void
setObject(id, viewerObject)
Sets a single object by its ID, overwriting any existing object with the same ID.
- Parameters:
id:string- The ID of the object.viewerObject:ViewerObject- The object to set.
- Returns:
void
setObjectEditor(objectEditor)
Opens or closes the object configuration editor.
- Parameters:
objectEditor:ObjectEditor- The editor configuration.
- Returns:
void
setObjectOverrides(objects)
Sets temporary overrides for object configurations.
- Parameters:
objects:(objects) => ObjectOverrides- The overrides to apply.
- Returns:
void
setObjects(objectMap, append?)
Sets multiple objects in the store.
- Parameters:
objectMap:ViewerObjectMap- The map of objects to set.append?:boolean- Iftrue, appends the objects instead of overwriting.
- Returns:
void
setOnObjectClicked(onObjectClicked?)
Registers a callback for object click events.
- Parameters:
onObjectClicked?:(id, position, viewportID) => void- The callback function.
- Returns:
void
setScanMetadata(metadata)
Sets metadata for the CBCT scan.
- Parameters:
metadata:ScanMetadata- The scan metadata.
- Returns:
void
setSelection(selection, force?)
Sets the selected objects.
- Parameters:
selection:ViewerSelection- The objects to select.force?:boolean- Iftrue, bypasses theuseConfigs.enableObjectSelectionsetting.
- Returns:
void
toggleObjectsVisibility(ids)
Toggles the visibility of a group of objects.
- Parameters:
ids:string[]- The IDs of the objects.
- Returns:
void
updateObject(id, viewerObject, clean?)
Updates an object by its ID, overriding only specified properties.
- Parameters:
id:string- The ID of the object.viewerObject:Partial<ViewerObject>- The properties to update.clean?:boolean- Iftrue, prevents setting the dirty flag.
- Returns:
void
updateObjects(viewerObjects, clean?)
Updates multiple objects simultaneously.
- Parameters:
viewerObjects:Record<string, Partial<ViewerObject>>- The objects to update.clean?:boolean- Iftrue, prevents setting the dirty flag.
- Returns:
void
The useObjects hook is a powerful tool for managing objects in the scene, offering fine-grained control over their state, selection, visibility, and interactions. By leveraging this hook, developers can create dynamic and interactive experiences within the @promaton/scan-viewer framework.